<?php
namespace App\Admin\Controllers\Ext;

class Status
{
    /**
     * add a grid here.
     */
    public function grid($grid,array $app)
    {
		$sarr = $app['sets']['status']['set'] ?? '';
		$sarr = str2arr($sarr);
		$app['grid_selectors']['status'] = ['title'=>'状态','option'=>$sarr,'scope'=>'status'];
		$grid->column('status', '状态')->editable('select', $sarr);	
		
		$grid->batchActions(function ($batch) use($sarr){
			foreach($sarr as $k=>$v){
				$v = '转为'.$v;
				$batch->add($v,new \App\Admin\Actions\Tools\BatchStatus($k));
			}
		});
	}

    /**
     * add a form here.
     */
    public function form($form,array $app)
    {
		$sarr = $app['sets']['status']['set'] ?? '';
		$form->select('status', '状态')->default(1)->options(str2arr($sarr));
    }

    public function show($show,array $app)
    {
		$show->field('status','状态');
	}


//api
	public function queryFor($model,array $app)
    {
		$status = request('status',1);
		return $model->where('status',$status);
	}
	public function queryFilters($filters,array $app)
    {
		$filters[] = 'status';
		return $filters;
	}
}
